package cn.JHai.rbac.controller;

import cn.JHai.rbac.RequiredPermission;
import cn.JHai.rbac.domain.Permission;
import cn.JHai.rbac.query.PageResult;
import cn.JHai.rbac.query.QueryObject;
import cn.JHai.rbac.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    PermissionService permissionService;

    /**
     * 显示permission，运用了分页
     * @param queryObject
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(QueryObject queryObject ,Model model){
        PageResult result = permissionService.query(queryObject);

        model.addAttribute("result",result);
        return "/permission/list";
    }

    /**
     *
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public String list(  Model model,Long id){
        permissionService.Delete(id);
        return "redirect:/permission/list";
    }


    @RequestMapping("input")
    public String input(Model model,Long id){
        if(id!=null){
            model.addAttribute("entity",permissionService.get(id));
        }
        return "permission/input";
    }

    @RequestMapping("saveOrUpdate")
    public String saveOrUpdate(Permission permission){
        permissionService.saveOrUpdata(permission);
        return "redirect:/permission/list";
    }

    @RequestMapping("reload")
    public String reload() {
        permissionService.reload();
        return "redirect:/permission/list";
    }

}
